package com.regis.comment;

/**
 * @author 计算机系 ITAEM 纱雾休比我老婆
 * @Description
 * @date 2022/7/28 4:35
 */
public class CodeMsg {
    private int code;//错误标识
    private String msg;//具体信息

    //通用
    public final static CodeMsg SUCCESS = new CodeMsg(200,"成功");
    public final static CodeMsg STATE_ERROR = new CodeMsg(401,"未登录");
    public final static CodeMsg DEFAULT = new CodeMsg(400,"失败");
    public final static CodeMsg SERVICE_ERROR = new CodeMsg(50001,"服务器错误");
    public final static CodeMsg PARAMETER_ERROR = new CodeMsg(50002,"参数错误");
    public final static CodeMsg NULL_ERROR = new CodeMsg(50003,"数据为空");
    public final static CodeMsg SIGN_ERROR = new CodeMsg(50004,"签名错误");


    @Override
    public String toString() {
        return "CodeMsg [code=" + code + ", msg=" + msg + "]";
    }

    public CodeMsg fillArgs(Object... args) {
        int code = this.code;
        String message = String.format(this.msg, args);
        return new CodeMsg(code, message);
    }

    public CodeMsg() {
    }

    public CodeMsg(int code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public CodeMsg(String msg){
        this.code = CodeMsg.DEFAULT.getCode();
        this.msg = msg;
    }

    public int getCode() {
        return code;
    }

    public String getMsg() {
        return msg;
    }
}
